package android.com.progress;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;

public class progrssActivi extends Activity {
	ProgressBar bar;
	TextView txt;
	int total = 0;
	boolean isRunning = false;

	Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			total = total + 1;
			String perc = String.valueOf(total).toString();
			txt.setText(perc + "% completed");
			bar.incrementProgressBy(5);
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
//		bar = (ProgressBar) findViewById(R.id.progress);
//		txt = (TextView) findViewById(R.id.txt);
		
		final RatingBar ratingbarIdicator = (RatingBar)findViewById(R.id.ratingbar_Indicator);
		ratingbarIdicator.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
			
			@Override
			public void onRatingChanged(RatingBar ratingBar, float rating,
					boolean fromUser) {
				ratingbarIdicator.setRating(rating);
				
			}
		});
	}

	public void onStart() {
		super.onStart();
		// reset the bar to the default value of 0
		bar.setProgress(0);
		// create a thread for updating the progress bar
		Thread background = new Thread(new Runnable() {
			public void run() {
				try {
					for (int i = 0; i < 20 && isRunning; i++) {
						// wait 1000ms between each update
						Thread.sleep(10000);
						handler.sendMessage(handler.obtainMessage());
					}
				} catch (Throwable t) {
				}
			}
		});
		isRunning = true;
		// start the background thread
		background.start();
	}

	public void onStop() {
		super.onStop();
		isRunning = false;
	}


	
	
	
	
}